package cn.assumejson.springframework.aop.aspectj.annotation;

import cn.assumejson.springframework.beans.factory.BeanFactory;
import cn.hutool.core.lang.Assert;

/**
 * @author gang.Li
 * @version 1.0
 * @since 1.0 2021/12/9 17:06
 */
public class BeanFactoryAspectInstanceFactory {

    private final BeanFactory beanFactory;

    private final String name;

    public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name) {
        this(beanFactory, name, null);
    }

    public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class<?> type) {
        Assert.notNull(beanFactory, "BeanFactory must not be null");
        Assert.notNull(name, "Bean name must not be null");
        this.beanFactory = beanFactory;
        this.name = name;
        Class<?> resolvedType = type;
        if (type == null) {
            resolvedType = beanFactory.getType(name);
            Assert.notNull(resolvedType, "Unresolvable bean type - explicitly specify the aspect class");
        }
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    public String getName() {
        return name;
    }
}
